const mongoose = require('mongoose');

const permissionSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
    trim: true,
  },
  code: {
    type: String,
    required: true,
    unique: true,
    trim: true,
  },
  type: {
    type: String,
    enum: ['menu', 'button'],
    required: true,
  },
  parentId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Permission',
    default: null,
  },
  path: {
    type: String,
    trim: true,
  },
  component: {
    type: String,
    trim: true,
  },
  icon: {
    type: String,
    trim: true,
  },
  sort: {
    type: Number,
    default: 0,
  },
  status: {
    type: Number,
    default: 1, // 1: 正常, 0: 禁用
  },
}, {
  timestamps: true,
});

const Permission = mongoose.model('Permission', permissionSchema);

module.exports = Permission; 